package com.powernode.controller;

import com.powernode.domain.SysMenu;
import com.powernode.model.Result;
import com.powernode.service.SysMenuService;
import com.powernode.util.AuthUtils;
import com.powernode.vo.MenuAndPermsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

/**
 * 菜单权限接口管理
 */
@Api("系统权限接口管理")
@RestController
@RequestMapping("sys/menu")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;

    @ApiOperation("查询登录用户的菜单和权限")
    @GetMapping("nav")
    public Result<MenuAndPermsVo> loadUserMenuPerms() {
        // 获取当前登录用户id
        Long userId = AuthUtils.getLoginUserId();
        // 查询当前登录用户的权限集合  ---> 哪些按钮
        Set<String> perms = AuthUtils.getPerms();
        // 根据用户id 查询菜单集合   ---->  左侧菜单栏
        Set<SysMenu> menus = sysMenuService.queryUserMenus(userId);
        // 创建菜单和权限集合对象
        MenuAndPermsVo menuAndPermsVo = new MenuAndPermsVo(menus , perms);
        return Result.success(menuAndPermsVo);
    }
}
